%%% creates an index for each individual
ind_id = kron(ones(per_n,1), kron([1:ind_n]', ones(draw_n,1))); 

%%% X_f generates the unobserved factor (proper to each individual) which
%%% depends on unobserved characteristics and on an orthogonal random term  
%%% drawn from a normal distribution with mean 0 and variance determined by
%%% the estimated structural coefficient
X_f=f_mean(i)+X_s*alpha(:,i)+randn(ind_n, char_n)*error_mag_i(i);





